Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: add highlight scope for type parameters #8660

Merged
merged 2 commits into from
Nov 3, 2023

Conversation

jmhain
Copy link
Contributor

@jmhain jmhain commented Oct 29, 2023

Highly generic code can be challenging to read when type parameters are highlighted the same as other types. This is especially true when the type parameters are not single letters, e.g. Fut is somewhat common in Rust.

So this PR adds a new highlighting scope for type parameters. I added it only for Rust as a proof-of-concept, but if accepted I'll update the queries for any other languages I'm familiar with (either in this PR or in a follow-up, whichever is preferred).

Here is a before and after with my in-progress port of the Codely theme.

image

image

Copy link
Member

@kirawi kirawi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@kirawi
Copy link
Member

kirawi commented Oct 30, 2023

There is also optional_type_parameter (which I didn't know was a thing until now) seen in

fn foo<T = Roo>() {
}

with an AST of

[source_file](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [2, 0]
  [function_item](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [1, 1]
    name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 3] - [0, 6]
    type_parameters: [type_parameters](https://tree-sitter.github.io/tree-sitter/playground#) [0, 6] - [0, 15]
      [optional_type_parameter](https://tree-sitter.github.io/tree-sitter/playground#) [0, 7] - [0, 14]
        name: [type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 7] - [0, 8]
        default_type: [type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 11] - [0, 14]
    parameters: [parameters](https://tree-sitter.github.io/tree-sitter/playground#) [0, 15] - [0, 17]
    body: [block](https://tree-sitter.github.io/tree-sitter/playground#) [0, 18] - [1, 1]

@jmhain
Copy link
Contributor Author

jmhain commented Oct 30, 2023

Thanks for catching that @kirawi, I pushed a commit to handle that case

@cd-a
Copy link
Contributor

cd-a commented Oct 30, 2023

Love it. Thanks!

As you mentioned, that would be awesome for other languages like TypeScript as well.

@jmhain
Copy link
Contributor Author

jmhain commented Oct 30, 2023

@cd-a I was planning on doing TypeScript next 🙂

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me 👍

@the-mikedavis the-mikedavis added A-theme Area: Theme and appearence related S-waiting-on-review Status: Awaiting review from a maintainer. A-language-support Area: Support for programming/text languages labels Nov 3, 2023
Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is generally a nice feature. Note that #1151 will cause issues here more frequently since generieren parameters often have larger scopes than function Parameters (impl Block in rust for example)

@pascalkuthe pascalkuthe merged commit 70bbbd7 into helix-editor:master Nov 3, 2023
6 checks passed
@jmhain jmhain deleted the type-parameter-highlights branch November 3, 2023 21:23
danillos pushed a commit to danillos/helix that referenced this pull request Nov 21, 2023
* rust: add highlight scope for type parameters

* handle optional type parameters
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
* rust: add highlight scope for type parameters

* handle optional type parameters
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
* rust: add highlight scope for type parameters

* handle optional type parameters
Vulpesx pushed a commit to Vulpesx/helix that referenced this pull request Jun 7, 2024
* rust: add highlight scope for type parameters

* handle optional type parameters
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
* rust: add highlight scope for type parameters

* handle optional type parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-support Area: Support for programming/text languages A-theme Area: Theme and appearence related S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants